#!/bin/bash
# 初始化centos服务器

#必须是root用户才可以执行
if [ $UID -ne 0 ]; then
    echo "Superuser privileges are required to run this script."
    echo "e.g. \"sudo $0\""
    exit 1
fi

#设置一下主机名
echo -n "please set the host name："
read hostname

if [[ ! $hostname ]]; then
  echo "$0 hostname is required"
  exit 1
fi

echo "setting host name to $hostname"
hostnamectl --static --transient --pretty set-hostname $hostname

resourcebasepath=$(cd `dirname $0`; cd ../resource; pwd) #/root/resource

yum -y install net-tools ntp lvm2 wget device-mapper

systemctl enable ntpd

# 安装nginx
yum -y install nginx
systemctl enable nginx.service
systemctl start nginx.service

# 安装tomcat，清华大学源，据说速度很快
echo "starting to install tomcat8"
cd $resourcebasepath
cd tomcat

tar -C /usr -xzf apache-tomcat-8.0.47.tar.gz

catalinaHome=`ls /usr/apache-tomcat* -d`

# tomcat空实例
cp tomcat_base.tar.gz ${catalinaHome}/
#  systemctl管理需要用到的tomcat.service
cp tomcat.service ${catalinaHome}/bin/

chown -R root:root ${catalinaHome}
chmod +x ${catalinaHome}/bin/*.sh

# jdbc
cd $resourcebasepath
cd jdbc
cp *.jar ${catalinaHome}/lib

# 设置环境变量
echo "export CATALINA_HOME=${catalinaHome}" >> /etc/environment

#export CATALINA_HOME=/usr/apache-tomcat-8.0.47

# 安装jdk

echo "export JAVA_HOME=/usr/lib/jvm/jre-1.8.0-openjdk" >> /etc/environment

# 资源目录
if [[ ! -e /data1 ]]; then
    mkdir /data1
fi





